package mysgoog.bot.algo;

import mysgoog.board.Board;
import mysgoog.board.DragonBoard;
import mysgoog.gtp.Color;
import mysgoog.gtp.Vertex;

public class PotentialConn {

	public static Vertex potenConn(Board board, Color color) {

		if (!(board instanceof DragonBoard))
			return null;

		DragonBoard db = (DragonBoard) board;
		Evaluator ev = new Evaluator(db);

		double con = 0, pon = 0;
		int connpo = -1;
		for (int i = 0; i < board.BOARD_ELEMNUM; i++) {
			if (board.isLegal(color, i)) {
				double tc = ev.connEvaluate(i, color);
				double tp = ev.evaluate(i, color);
				if (con < tc || (con == tc && pon < tp)) {
					con = tc;
					pon = tp;
					connpo = i;
				}
			}
		}
		int t = board.getTurn();
		if ((t < 30 && con >= t * 0.7) || (t >= 30 && t < 50 && con >= t * 0.5)
				|| (t >= 50 && t < 100 && con >= t * 0.35)
				|| (t >= 100 && con >= t * 0.3))
			return new Vertex(connpo);
		else
			return null;
	}
}
